package com.yvon.core.page;

import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.reflection.property.PropertyNamer;

import java.io.Serializable;


@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SearchParam implements Serializable {
    private static final long serialVersionUID = 5094096637006312823L;
    private String fieldName;
    private Operator operate;
    private String value;
    private String value1;

    private static String getColumn(String prefix, SerializedLambda lambda) {
        String name = PropertyNamer.methodToProperty(lambda.getImplMethodName());
        if (!Strings.isNullOrEmpty(prefix)) {
            name = prefix.concat(name);
        }

        return name;
    }


    public static enum Operator {
        eq,
        ne,
        gt,
        ge,
        lt,
        le,
        between,
        notBetween,
        like,
        notLike,
        in,
        notIn,
        isNull,
        isNotNull;

        private Operator() {
        }
    }
}
